package reflectCus;

import java.lang.reflect.Field;
import java.util.Scanner;
//Class.forName(String className).newInstance实例化对象;
public class ReflectDemo2 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        System.out.println(new Person());

        Class cls=Person.class;
        Object o=cls.newInstance();

        System.out.println(o);

        Class cls2=Class.forName("reflectCus.Person");
        Object o2=cls2.newInstance();
        System.out.println(o2);

        try {
            Field f=cls2.getField("name");
            System.out.println(f.get(o2));
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        Class cls3=Class.forName(s);
        Object o3=cls3.newInstance();
        System.out.println(o3);

    }
}
